package app.controller.context
{
	import app.model.global.ApplicationModel;
	
	import app.view.event.MainEvent;
	
	import app.controller.mediator.MainMediator;
	import app.controller.command.LoadConfigCommand;
	import app.controller.command.SharedObjectCommand;
	
	import app.service.loader.ConfigURLLoaderService;
	import app.service.local.SharedObjectService;
	import app.service.local.SharedObjectServiceInterface;
	import app.service.loader.URLLoaderServiceInterface;
	import app.service.event.SharedObjectServiceEvent;
	import app.service.event.URLLoaderServiceEvent;

	import flash.display.DisplayObjectContainer;
	
	import org.robotlegs.mvcs.Context;
	import app.view.module.MainInterface;
	
	public class MainContext extends Context
	{
		public function MainContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
		{
			trace("MainContext");
			super(contextView, autoStartup);
			
		}
		
		override public function startup():void
		{
			trace("MainContext startup");
			
			//there are 3 ways to inject: mediatorMap, commandMap, injector
			//mediatorMap for view mediation
			//commandMap for executing processes via events
			//injector for models (actors), RemoteObjects, HTTPServices, factory classes, or virtually ANY class/instance 
			//that you might need as dependencies for your your application objects
			//there are a few ways to use the injector: mapValue, mapSingleton, mapClass, mapSingletonOf - read the docs to learn more
			//https://github.com/robotlegs/robotlegs-framework/wiki

			//injector - classes
			//injector.mapSingletonOf(ShoppingListInterface, ShoppingList);
			
			//mediatorMap
			//mediatorMap.mapView("app.view.module.IndexGaiaPageModule", IndexPageMediator, IndexPageInterface);
			
			//injector - models
			injector.mapSingleton(ApplicationModel);
			
			//injector - services
			injector.mapSingletonOf(URLLoaderServiceInterface, ConfigURLLoaderService, "configLoader");
			//injector.mapSingletonOf(URLLoaderServiceInterface, ShopURLLoaderService, "shopLoader");
			injector.mapSingletonOf(SharedObjectServiceInterface, SharedObjectService);
			
				
			//commandMap
			commandMap.mapEvent(URLLoaderServiceEvent.LOAD_CONFIG, LoadConfigCommand, URLLoaderServiceEvent);
			commandMap.mapEvent(URLLoaderServiceEvent.CONFIG_DATA_LOADED, LoadConfigCommand, URLLoaderServiceEvent);
			commandMap.mapEvent(SharedObjectServiceEvent.SHARED_OBJECT_INITIALIZED, SharedObjectCommand, SharedObjectServiceEvent);
			commandMap.mapEvent(SharedObjectServiceEvent.INIT_SHARED_OBJECT, SharedObjectCommand, SharedObjectServiceEvent);
			commandMap.mapEvent(SharedObjectServiceEvent.SAVE_VALUE_WITH_KEY, SharedObjectCommand, SharedObjectServiceEvent);
			commandMap.mapEvent(SharedObjectServiceEvent.CLEAR_ALL, SharedObjectCommand, SharedObjectServiceEvent);


			//this maps the Main class, enables it to participate in framework business
			//should be mapped last - don't add mappings below this, add them above 
			mediatorMap.mapView(Main, MainMediator, MainInterface);
			mediatorMap.createMediator(contextView);
		}
	}
}